home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1995 June / MacFormat 25.iso / Shareware City / Developers / OutOfPhase1.1 Source / OutOfPhase Folder / 64BitMath.c < prev    next >
Text File  |  1995-01-04  |  3KB  |  77 lines

  1. /* 64BitMath.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "64BitMath.h"
  31.  
  32.  
  33. #if STRUCTUREBASED64BIT
  34. #if ENABLEGENERICLONGLONG
  35. /* add two longlongs:  *L = *L + *R */
  36. void                            LongLongAdd(LongLongRec* L, LongLongRec* R)
  37.     {
  38.         double                    Overflow;
  39.         double                    LowTemp;
  40.  
  41.         ERROR(sizeof(long) == 8,PRERR(AllowResume,
  42.             "LongLongAdd:  64-bit longs are available on this system"));
  43.  
  44.         /* low order stuff */
  45.         LowTemp = (double)((L->Low32Bits + R->Low32Bits) & 0xffffffff);
  46.  
  47.         /* check for overflow */
  48.         Overflow = 0;
  49.         if (LowTemp < (double)L->Low32Bits + (double)R->Low32Bits)
  50.             {
  51.                 Overflow = 1;
  52.             }
  53.  
  54.         /* high order stuff */
  55.         L->Low32Bits = LowTemp;
  56.         L->High32Bits = L->High32Bits + R->High32Bits + Overflow;
  57.     }
  58. #endif
  59. #endif
  60.  
  61.  
  62. #if STRUCTUREBASED64BIT
  63. /* initialize a longlong with a double precision floating point value */
  64. void                            Double2LongLong(double D, LongLongRec* L)
  65.     {
  66.         if (D >= 0)
  67.             {
  68.                 L->High32Bits = (signed long)D;
  69.             }
  70.          else
  71.             {
  72.                 L->High32Bits = -(signed long)(-D);
  73.             }
  74.         L->Low32Bits = (D - L->High32Bits) * 4294967296.0;
  75.     }
  76. #endif
  77.